#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef int ElemType;
typedef struct LNode{
    ElemType data;
    struct LNode *next;
}LNode, *LinkList;

bool listInit(LinkList L);
LinkList list_headInsert(LinkList L);
LinkList list_TailInsert(LinkList L);
void printList(LinkList L);

int main(){
    LinkList L;
    L = list_TailInsert(L);
    printList(L);
    return 0;
}

bool listInit(LinkList L){
    L = (LNode *)malloc(sizeof(LNode));
    if(L==NULL) return false;
    L->next = NULL;
    return true;
}

//前插法
LinkList list_headInsert(LinkList L){
    L = (LNode *)malloc(sizeof(LNode));
    L->next = NULL;
    int inp = -1;
    if(L==NULL) return false;
    printf("PLease input the data:\n");
    while(inp!=9999){
        scanf("%d", &inp);
        if(inp==9999) break;
        LNode *s = (LNode *)malloc(sizeof(LNode));
        s->data = inp;
        s->next = L->next;
        L->next = s;
    }
    return L;   
}

//后插法
LinkList list_TailInsert(LinkList L){
    L = (LNode *)malloc(sizeof(LNode));
    L->next = NULL;
    LNode *p = L;
    int inp = -1;
    if(L==NULL) return false;
    printf("PLease input the data:\n");
    while(inp!=9999){
        scanf("%d", &inp);
        if(inp==9999) break;
        LNode *s = (LNode *)malloc(sizeof(LNode));
        s->data = inp;
        p->next = s;
        p = s;
    }
    p->next = NULL;
    return L;
}

void printList(LinkList L){
    if(L==NULL) return;
    LNode *p = L->next;
    printf("The linklist include these data:\n");
    while(p!=NULL){
        printf("%d\n",p->data);
        p = p->next;
    }
}